package com.geoboard.service;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.geoboard.fragments.MapFrag;

public class RequestErrorListener implements Response.ErrorListener {
	
	/**** Members **************************************************/
	private Context mContext;
	private String TAG = this.getClass().getSimpleName();

	public RequestErrorListener (MapFrag mapFrag) {
		mContext = mapFrag.getActivity();
	}
	
	@Override
	public void onErrorResponse(VolleyError error) {
    	if (error.getMessage() != null) {
    		Log.e(TAG, error.getMessage());
	        Toast.makeText(mContext,
		        		String.format("%d - server unavailable, %s", 
		        				error.networkResponse.statusCode, error.getMessage()),
		        		Toast.LENGTH_SHORT).show();
    	} else {
    		Log.e(TAG, "error is null - usually means server unavailable?");
	        Toast.makeText(mContext,
	        		String.format("Server unavailable"),
	        		Toast.LENGTH_SHORT).show();
    	}
	}

}
